use common::file_system::deserialize_toml;
use common::model::Project;

#[test]
fn test_deserialize_from_toml() {
    let toml_str = r#"
project_name="todolist"

[[proxies]]
route_name= "/api"
target = "http://127.0.0.1:8080"

[[project_deps]]
url="git+https://gitee.com"
is_dev=false
"#;

    let server: Project = deserialize_toml(toml_str).expect("Deserialization failed");
    let proxies = server.proxies.expect("proxies 反序列化失败");
    assert_eq!(proxies.len(), 1);
    assert_eq!(proxies[0].route_name, "/api");
    assert_eq!(proxies[0].target, "http://127.0.0.1:8080");
}

#[test]
fn test_deserialize_from_toml_missing_fields() {
    let toml_str = r#"
            [[proxies]]
            route_name = "/api"
            # target field is missing
        "#;

    let result = deserialize_toml::<Project>(toml_str);
    assert!(
        result.is_err(),
        "Expected deserialization to fail due to missing 'target' field"
    );
}
